'use strict';
const db = uniCloud.database()
const coll = db.collection('xinyuan')
const coll1 = db.collection('user')
exports.main = async (event, context) => {
	let res = await coll1.where({
		openid: event.openid
	}).get()
	console.log(res)
	if (res.data[0].status != 0) {
		let res1 = await coll.add({
			openid: event.openid,
			xinyuan: event.xinyuan,
			zan: 0,
			status: 0
		})
		console.log(res1)
		let res2 = await coll1.where({
			openid: event.openid
		}).update({
			status: 0,
			xinyuan: res1.id
		})
		return {
			status: 1,
			msg: '提交心愿成功!'
		}
	} else {
		return {
			status: 0,
			msg: '您已提交过心愿!'
		}
	}

};
